package com.bg.print.controller;

import com.bg.print.entity.OrderDetailsEntity;
import com.bg.print.service.OrderDetailsService;
import com.bg.print.utils.PageUtils;
import com.bg.print.utils.R;
import com.bg.print.variable.Enabled;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;




/**
 * 订单明细
 *
 * @author liuxvru
 * @email liuxvru@163.com
 * @date 2024-03-25 17:50:46
 */
@Tag(name = "订单明细")
@RestController
@RequestMapping("/orderdetails")
public class OrderDetailsController {
    @Autowired
    private OrderDetailsService orderDetailsService;

    /**
     * 列表
     */
    @Operation(summary ="列表")
    @GetMapping("/list")
    @PreAuthorize("hasAuthority('ADMIN') or hasAuthority('MERCHANT')")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = orderDetailsService.queryPage(params);
        return R.ok().put("data", page);
    }

    @Operation(summary ="根据订单id查询订单明细")
    @GetMapping("/list/{orderId}")
    public R getByOrderId(@PathVariable("orderId")Long id){
        List<OrderDetailsEntity> list= orderDetailsService.getByOrderId(id);
        return R.ok().put("data", list);
    }


    /**
     * 信息
     */
    @Operation(summary ="信息")
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		OrderDetailsEntity orderDetails = orderDetailsService.getById(id);
        return R.ok().put("data", orderDetails);
    }

    /**
     * 保存
     */
    @Operation(summary ="保存")
    @PostMapping("/save")
    public R save(@RequestBody OrderDetailsEntity orderDetails){
        orderDetails.setEnabled(Enabled.USING.getCode());
		orderDetailsService.save(orderDetails);
        return R.ok();
    }

    /**
     * 修改
     */
//    //@Operation(summary ="修改")
//    @PutMapping("/update")
//    public R update(@RequestBody OrderDetailsEntity orderDetails){
//		orderDetailsService.updateById(orderDetails);
//        return R.ok();
//    }



    /**
     * 删除
     */
//    @Operation(summary ="删除")
//    @DeleteMapping("/delete")
//    @PreAuthorize("hasAuthority('BUYER')")
//    public R delete(@RequestBody Long[] ids){
//		orderDetailsService.removeByIds(Arrays.asList(ids));
//        return R.ok();
//    }

}
